import {
	fileURLToPath,
	URL
} from 'node:url'

import {
	defineConfig
} from 'vite'
import vue from '@vitejs/plugin-vue'
//引入插件
import AutoImport from 'unplugin-auto-import/vite';
//按需导入 ElementPlus
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
// https://vitejs.dev/config/
export default defineConfig({
	plugins: [
		vue(),
		//配置插件
		AutoImport({
			resolvers: [ElementPlusResolver()],
			imports: ['vue', 'vue-router']
		}),
		Components({
		      resolvers: [ElementPlusResolver()],
		}),
	],
	resolve: {
		alias: {
			'@': fileURLToPath(new URL('./src',
				import.meta.url))
		}
	},
	server: {
		port: 3000,
		host: '0.0.0.0',
		proxy: {
			'/api': {
				target: 'http://47.107.85.12:6066/',
				// target就是你要访问的目标地址，可以是基础地址，这样方便在这个网站的其他api口调用数据
				ws: true,
				changeOrigin: true,
				rewrite: (path) => path.replace(/^\/api/, ''),
				// 要记得加rewrite这句
			},
		},
	},
	// server:{
	// 	host: '0.0.0.0',
	// 	port: 3030,
	// 	proxy:{
	// 		'/api':'http://47.107.85.12:6066/', //请求对象http://47.107.85.12:6066/    http://192.168.1.2:6066/
	// 	}
	// }
})
